package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author dxt
 * @create 2025-07-16-14:41
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 客户列表分页（名称模糊查询）
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @RequestMapping("/list")
    public Map<String, Object> getCustomerListPage(Integer page, Integer rows, String customerName) {
        return customerService.getCustomerListPage(page, rows, customerName);
    }

    /**
     * 保存或更新客户信息
     * @param customerId
     * @param customer
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveOrUpdate(@RequestParam(value = "customerId", required = false) Integer customerId, @ModelAttribute Customer customer) {
        customerService.saveOrUpdate(customerId, customer);
        return new ServiceVO(100, "操作成功", null);
    }

    /**
     * 删除客户信息
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(String ids) {
        customerService.delete(ids);
        return new ServiceVO(100, "操作成功", null);
    }

    /**
     * 查询客户下拉框数据
     * @param q 客户名称
     * @return
     */
    @PostMapping("getComboboxList")
    public List<Customer> getComboboxList(String q) {
        return customerService.getComboboxList(q);
    }
}
